﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace TestWPF
{
    public class CylinderProgress : INotifyPropertyChanged
    {
        private double progress = 0;
        private bool isInspiration = false;

        public event PropertyChangedEventHandler PropertyChanged;

        public double Progress
        {
            get { return progress; }
            set
            {
                if ((value <= 100) && (value >= 0))
                {
                    if (progress != value)
                    {
                        progress = value;
                        NotifyPropertyChanged("Progress");
                    }
                }
            }
        }

        /* 是否吸气 */
        public bool IsInspiration
        {
            get { return isInspiration; }
            set
            {
                if (isInspiration != value)
                {
                    isInspiration = value;
                    NotifyPropertyChanged("IsInspiration");
                }
            }
        }

        public CylinderProgress(double p = 0, bool ins = true)
        {
            Progress = p;
            IsInspiration = ins;
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }

    public class ProgressConver : IValueConverter
    {
        //当值从绑定源传播给绑定目标时，调用方法Convert
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double progress = (double)value;
            double total = System.Convert.ToDouble(parameter);

            return -total + (total * (progress / 100));
        }
        //当值从绑定目标传播给绑定源时，调用此方法ConvertBack
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ProgressConver2 : IValueConverter
    {
        //当值从绑定源传播给绑定目标时，调用方法Convert
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double progress = (double)value;
            double total = System.Convert.ToDouble(parameter);

            return (total - 1.0) * (progress / 100) + 1.0;
        }
        //当值从绑定目标传播给绑定源时，调用此方法ConvertBack
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
